// 路由
import Vue from "vue";
import VueRouter from "vue-router";
// import Login from "../components/Login.vue";
// import Home from "../components/Home.vue";
// import Welcome from '../components/Welcome.vue'
const Login = () => import(/* webpackChunkName: "login_home_welcome" */ '../components/Welcome.vue')
const Home = () => import(/* webpackChunkName: "login_home_welcome" */ '../components/Home.vue')
const  Welcome= () => import(/* webpackChunkName: "login_home_welcome" */ '../components/Welcome.vue')
// import Users from '../components/user/Users.vue'
// import Rights from '../components/power/Rights.vue'
// import Roles from '../components/power/Roles.vue'
const  Users= () => import(/* webpackChunkName: "users_rights_roles" */ '../components/Users.vue')
const  Rights= () => import(/* webpackChunkName: "users_rights_roles" */ '../components/Rights.vue')
const  Roles= () => import(/* webpackChunkName: "users_rights_roles" */ '../components/Roles.vue')
// import Category from '../components/goods/Category.vue'
// import Params from '../components/goods/Params.vue'
const  Category= () => import(/* webpackChunkName: "category_params" */ '../components/Category.vue')
const  Params= () => import(/* webpackChunkName: "category_params" */ '../components/Params.vue')
// import GoodsList from '../components/goods/List.vue'
// import GoodsAdd from '../components/goods/GoodsAdd.vue'
const  GoodsList= () => import(/* webpackChunkName: "goodsList_goodsAdd" */ '../components/GoodsList.vue')
const  GoodsAdd= () => import(/* webpackChunkName: "goodsList_goodsAdd" */ '../components/GoodsAdd.vue')
// import Order from '../components/order/Order.vue'
// import Report from '../components/report/Report.vue'
const  Order= () => import(/* webpackChunkName: "order_report" */ '../components/Order.vue')
const  Report= () => import(/* webpackChunkName: "order_report" */ '../components/Report.vue')

Vue.use(VueRouter);
const thisRouter = new VueRouter({
  routes: [
    { path: "/", redirect: "/login" },
    {
      path: "/login",
      component: Login
    },
    {
      path: "/home",
      component: Home,
      redirect: '/welcome',
      children: [{
        path: '/welcome',
        component: Welcome
      }, {
        path: '/users',
        component: Users
      }, {
        path: '/rights',
        component: Rights
      }, {
        path: '/roles',
        component: Roles
      }, {
        path: '/categories',
        component: Category
      }, {
        path: '/params',
        component: Params
      }, {
        path: '/goods',
        component: GoodsList
      }, {
        path: '/goods/add',
        component: GoodsAdd
      }, {
        path: '/orders',
        component: Order
      }, {
        path: '/reports',
        component: Report
      }]
    }
  ]
});
// 挂载路由守卫
// to,from,next是形参
thisRouter.beforeEach((to, from, next) => {
  if (to.path == "/login") {
    return next();
  }
  const tokenStr = window.sessionStorage.getItem("browserToken");
  if (!tokenStr) {
    next("/login");
  }
  next();
});
export default thisRouter;
